<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<%=path %>/layui/css/layui.css">
  <link rel="stylesheet" href="<%=path %>/layui/css/lxq.css">
    <script type="text/javascript" src="<%=path %>/layui/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=path %>/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=path %>/layui/util.js" charset="utf-8"></script>
</head>
<body>
<div class="lxq-body">
	<div class="layui-row lxq-address">
		位置：信息管理>部门信息
		<hr>
	</div>





  <div class="layui-row layui-col-space10">
   		  部门名：
		  <div class="layui-inline">
		    <input class="layui-input" name="infoName" id="infoName" autocomplete="off">
		  </div>
		  <button class="layui-btn" data-type="reUnit">搜索</button><button class="layui-btn" data-type="addUnit">添加</button>
		  
		  
      <table class="layui-hide" id="unit_form" lay-filter="unit"></table> 
 
 		

</div>              
          

 
<script>
var academyId="";
layui.use(['table'], function(){
  var table = layui.table;
  
  function findUnit(){
	  var unitName = $('#infoName');
      table.reload("unit_form",{
    	  url:'<%=path %>/biz/Info_list'
    	  ,where: {
    		  infoName: unitName.val(),
    		  level: 4
    	  }
          ,page: {
            curr: 1 //重新从第 1 页开始
          }
      });
  }

  
  //表格加载
  //学院部分
  table.render({
	    elem: '#unit_form'
	    ,url:'<%=path %>/biz/Info_list'
   	    ,where: {
   		  level: 4
   	    }
	    ,page: true
	    ,cols: [[
	      {field:'infoName',  title: '部门名'}
	      ,{field:'infoParent',  title: '所属学院'}
	      ,{field:'infoMark',  title: '备注'}
	      ,{fixed: 'right', title:'操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
 		 ,id: 'unit_form'
	  });
  
  
	  //监听工具条
	  table.on('tool(unit)', function(obj){
	    var data = obj.data;
		if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
	        obj.del();
	        $.post('<%=path %>/biz/Info_del',{"id":data.id},function(){});
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
	    	  layer.open({
	    		  title: '修改部门',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=path %>/biz/Info_toEditUnit?id='+data.id,
	    		  end : function(layero, index){
	    			  findUnit();
	    		  }
	    	  });
	    }
	  });
	  
  	
  	
  //事件触发	
  	var $ = layui.$, active = {
		  //模糊搜索学院
	  reUnit: function(){
		  findUnit();
	      //执行重载
	    },
	    
    addUnit: function(){
    	  layer.open({
    		  title: '添加部门',
    		  type: 2, 
    		  area: ['50%', '90%'],
    		  content: '<%=basePath%>/biz/Info_toAddUnit',
    		  end : function(layero, index){
    			  findUnit();
    		  }
    	  });
    }
	    
 
	};
	  
	  $('.layui-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
		//监听动态元素
	    $('.active').on('click','.layui-btn', function () {
		    var type = $(this).data('type');
		    active[type] ? active[type].call(this) : '';
	    });
  
});
</script>



    <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>

</body>
</html>